package com.zhongya.example.fragment.myview.study1

import android.animation.ValueAnimator
import android.view.View
import android.view.animation.*
import com.zhongya.example.R
import com.zhongya.example.databinding.ExampleFragmentViewStudyBinding
import com.zhongya666.library.base.fragment.BaseDbFragment
import com.zhongya666.library.base.fragment.BaseFragment

class ViewStudyFragment : BaseDbFragment<ExampleFragmentViewStudyBinding>(R.layout.example_fragment_view_study) {

    var animation1 : Animation? = null
    var animation2 : Animation? = null
    var animation3 : Animation? = null
    var animation4 : Animation? = null

    override fun initView() {
//        initsaoMiaoDongHua()
        mDatabind.btnDonghua.setOnClickListener {
//            chazhiqi()
        }
        mDatabind.include1.tv.setOnClickListener {
//            startSaoMiaoDongHua()
        }
    }

    override fun createObserver() {
    }

    override fun lazyLoadData() {
    }

    /*
    * 插值器
    *
    * */
    fun chazhiqi(){
        val animation = AnimationUtils.loadAnimation(requireContext(),R.anim.translateanim)
//            animation.interpolator = AccelerateDecelerateInterpolator() //加速减速插值器
//        animation.interpolator = AccelerateInterpolator() // 加速插值器
//        animation.interpolator = DecelerateInterpolator() // 减速插值器
        animation.interpolator = LinearInterpolator() // 线性插值器
//        animation.interpolator = BounceInterpolator() //弹跳插值器
//        animation.interpolator = AnticipateInterpolator(2f)//初始偏移插值器
//        animation.interpolator = OvershootInterpolator(2f)//结束偏移插值器
//        animation.interpolator = AnticipateOvershootInterpolator(2f,1.5f) //初始结束偏移插值器
        animation.interpolator = CycleInterpolator(3f) //循环插值器
        mDatabind.tv.startAnimation(animation)
    }

    fun initsaoMiaoDongHua(){
        animation1 = AnimationUtils.loadAnimation(requireContext(),R.anim.scale_alpha_anim)
        animation2 = AnimationUtils.loadAnimation(requireContext(),R.anim.scale_alpha_anim)
        animation3 = AnimationUtils.loadAnimation(requireContext(),R.anim.scale_alpha_anim)
        animation4 = AnimationUtils.loadAnimation(requireContext(),R.anim.scale_alpha_anim)
    }
    fun startSaoMiaoDongHua(){
        mDatabind.include1.iv1.startAnimation(animation1)
        animation2?.startOffset = 500
        mDatabind.include1.iv2.startAnimation(animation2)
        animation3?.startOffset = 1000
        mDatabind.include1.iv3.startAnimation(animation3)
        animation4?.startOffset = 1500
        mDatabind.include1.iv4.startAnimation(animation4)
    }

    /*
    * 属性动画
    * 自定义插值器
    * */
    fun myChaZhiQi(){
        val animator = ValueAnimator.ofInt(0,300)
        animator.addUpdateListener {
            val curValue = it.animatedValue

        }
    }

}